package com.jin.工厂模式.简单工厂模式.顺从.service.Impl;

import com.alibaba.fastjson.JSON;
import com.jin.工厂模式.简单工厂模式.违背.goods.DeliverReq;
import com.jin.工厂模式.简单工厂模式.违背.goods.GoodsService;
import com.jin.工厂模式.简单工厂模式.顺从.service.ICommodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class GoodsCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(GoodsCommodityService.class);
    private GoodsService goodsService = new GoodsService();
    @Override
    public void sendCommodity(String uid, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(uid));
        deliverReq.setUserPhone(queryUserPhoneNumber(uid));
        deliverReq.setSku(commodityId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("ConsigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("ConsigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("ConsigneeUserAddress"));
        Boolean isSuccess = goodsService.deliverGoods(deliverReq);
        logger.info("请求参数实物商品=> uid:{} commodityId:{} bizId:{} extMap:{}",uid,commodityId,bizId, JSON.toJSON(extMap));
        logger.info("测试结果实物商品:{} ",isSuccess);
        if ((!isSuccess)) throw new RuntimeException("实物商品发放失败");

    }

    private String queryUserName(String uId) {
        return "花花";
    }

    private String queryUserPhoneNumber(String uId) {
        return "15200101232";
    }


}
